package com.qhhc.hospital.controller;

import com.qhhc.hospital.entity.Orders;
import com.qhhc.hospital.service.IOrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class OrdersController {
    @Autowired
    IOrdersService ordersService;

    @RequestMapping("/insertOrders")
    public String insertOrders(@RequestBody Orders orders){
        ordersService.insert(orders);
        return "success";
    }

    @RequestMapping("/getAllOrders")
    public List<Orders> getAllOrders(){
        List<Orders> orders = ordersService.selectAll();
        return orders;
    }

    @RequestMapping("/getOrders/{oId}")
    public Orders getOrdersById(@PathVariable("oId") Integer oId){
        return ordersService.selectById(oId);
    }
    
    @RequestMapping("/getOrdersByPatient/{pId}")
    public List<Orders> getOrdersByPatientId(@PathVariable("pId") Integer pId){
        return ordersService.selectByPatientId(pId);
    }
    
    @RequestMapping("/getOrdersByDoctor/{dId}")
    public List<Orders> getOrdersByDoctorId(@PathVariable("dId") Integer dId){
        return ordersService.selectByDoctorId(dId);
    }

    @RequestMapping("/updateOrders")
    public String updateOrders(@RequestBody Orders orders){
        ordersService.update(orders);
        return "success";
    }

    @RequestMapping("/deleteOrders/{oId}")
    public String deleteOrders(@PathVariable("oId") Integer oId){
        ordersService.delete(oId);
        return "success";
    }
} 